package com.bowen.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RetryRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * Created by zhangbw on 2018/11/26
 * Describe：SpringCloud相关配置
 */
@Configuration
public class SpringCloudConfig {

    /**
     * 调用服务模版对象
     * @return
     */
    @Bean
    @LoadBalanced  //引入Ribbon负载均衡 默认轮询机制
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }

    /**
     * 自定义轮询算法-重试机制
     * @return
     */
    @Bean
    public IRule myRule(){
        return new RetryRule();
    }

}
